<?php
namespace app\erp\controller;

use app\erp\model\Returneddb;
use app\erp\model\Sitedb;

class Returned extends Base
{

    protected $db;

    protected $cols = array(
        array(
            'field' => 'returned_id',
            'width' => 40,
            'title' => 'ID',
            'type' => 'checkbox',
            'fixed' => 'left'
        ),
        array(
            'field' => 'order_no',
            'width' => 200,
            'title' => '订单号'
        ),
        array(
            'field' => 'returned_state',
            'width' => 60,
            'title' => '状态',
            'templet' => '#returned_stateTpl'
        ),
        array(
            'field' => 'goods_sku',
            'width' => 200,
            'title' => '商品编号'
        ),
        array(
            'field' => 'goods_name',
            'width' => 300,
            'title' => '商品名称'
        ),
        array(
            'field' => 'returned_num',
            'width' => 60,
            'title' => '数量'
        ),
        array(
            'field' => 'create_time',
            'width' => 120,
            'title' => '申请时间'
        ),
        array(
            'field' => 'returned_reason',
            'width' => 200,
            'title' => '原因'
        ),
        
        array(
            'fixed' => 'right',
            'width' => 80,
            'toolbar' => '#returned_tool'
        )
    );

    public $post = array();

    public function _initialize()
    {
        parent::_initialize();
        $request = request();
        $param = $request->param();
        $this->post = $param;
        $this->db = new Returneddb();
        $this->db->param = $this->post;
    }

    public function index()
    {
        // 获取分站信息
        $sitedb = new Sitedb();
        $get_site = $sitedb->ajaxFind(SITE_ID);
        $this->assign('get_site', $get_site);
        $this->assign('cols', json_encode($this->cols));
        return $this->fetch();
    }

    public function ajaxList()
    {
        if (! isset($this->post['returned_type'])){
            $this->post['returned_type'] = 1;
        }
        $this->db->param = $this->post;
        $return = $this->db->ajaxSelect();
        $this->layuiReturn($return['data'], $return['count']);
    }
    // 确认收到回寄产品
    public function saveData(){
        $return = $this->db->ajaxSave();
        $this->layuiReturn('回寄产品已收到',1);
    }
}